Skip to content

Complete support for dynamic container names #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed

Conversation

helderco
Copy link
Owner

@helderco helderco commented Jul 8, 2017

This is my attempt to solve the same nginx-proxy#205 issue.

In Swarm Mode and Docker Cloud, container names are dynamic. nginx-proxy#181 solved this partially with a label on jwilder/nginx-proxy but not if they're separate containers. nginx-proxy#126 tries a different approach, but I think using a label is a better one.

This PR simply adds a com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen=true label to the docker-gen container.

It also moves the label related detection to runtime (functions.sh: nginx-reload) instead of startup time (entrypoint.sh), because the nginx and docker-gen containers could be redeployed during the lifecycle of the letsencrypt companion, and thus, getting different ids.

There's also a new assumption in that I think it's simpler to just recommend using the label instead of volumes-from to detect the nginx-proxy container. The reason is that in some environments (like mine), you can't use volumes-from, but I think you can always use labels.

Note: If you're wandering why I've chosen not to set the variables NGINX_DOCKER_GEN_CONTAINER and NGINX_PROXY_CONTAINER, that's because we can use them to make sure an explicitly set container name takes precedence over a label.

Now I'm running a successful separate containers deployment in Swarm Mode, here's my stack:

version: '3.2'
services:
  nginx:
    image: nginx:alpine
    ports:
      - 80:80
      - 443:443
    volumes:
      - ./nginx/conf.d:/etc/nginx/conf.d
      - ./nginx/vhost.d:/etc/nginx/vhost.d
      - ./nginx/certs:/etc/nginx/certs
      - ./nginx/letsencrypt:/usr/share/nginx/html
    labels:
      - com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy=true
    deploy:
      placement:
        constraints:
          - node.role == manager

  dockergen:
    image: helder/docker-gen
    command: -notify "docker-label-sighup com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy" -watch /etc/docker-gen/templates/nginx.tmpl /etc/nginx/conf.d/default.conf
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ./nginx.tmpl:/etc/docker-gen/templates/nginx.tmpl
      - ./nginx/conf.d:/etc/nginx/conf.d
      - ./nginx/vhost.d:/etc/nginx/vhost.d
      - ./nginx/certs:/etc/nginx/certs
    labels:
      - com.github.jrcs.letsencrypt_nginx_proxy_companion.docker_gen=true
    deploy:
      placement:
        constraints:
          - node.role == manager

  letsencrypt:
    image: helder/letsencrypt-nginx-proxy-companion:latest
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./nginx/conf.d:/etc/nginx/conf.d
      - ./nginx/vhost.d:/etc/nginx/vhost.d
      - ./nginx/certs:/etc/nginx/certs
      - ./nginx/letsencrypt:/usr/share/nginx/html
    deploy:
      placement:
        constraints:
          - node.role == manager

As you can see, I'm also using a custom helder/docker-gen image which simply adds a docker-label-sighup script that allows me to reload the nginx container from a label, because... well, dynamic names. jwilder/docker-gen doesn't support reloading containers with dynamic names (yet).

Helder Correia added 5 commits July 6, 2017 22:03
@helderco
Copy link
Owner Author

helderco commented Jul 8, 2017

Wrong repo 🤦‍♂️

@helderco helderco closed this Jul 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant